<!DOCTYPE html>
<html lang="zh-cn">
  <head>
    <title><!--{if $user}-->欢迎加入<!--{else}-->新用户注册<!--{/if}--> <!--{$site.title}-->_<!--{$site.seotitle}--></title>
    <meta name="keywords" content="<!--{$site.keywords}-->" />
    <meta name="description" content="<!--{$site.description}-->"/>
    <!--{iCMS:public:ui}-->
    <link rel="stylesheet" href="<!--{$site.urls.tpl}-->/static/css/user.css" type="text/css" />
    <script>
      //初始化注册接口
      $(function() {
          var register = $("#register-box");
          $("input", register).click(function() {
              if (!$(this).data('check')) {
                  tip({
                      forward: this.name,
                      msg: 'def'
                  });
              }
          }).blur(function() {
              check_form(this);
          });
          $("#register_submit").click(function(event) {
              event.preventDefault();
              var checkform = false,
                  param = {};
              $("input", register).each(function() {
                  check_form(this);
              }).each(function() {
                  if (!$(this).data('check')) {
                      checkform = true;
                      return false;
                  }
                  if (this.name) {
                      param[this.name] = this.value;
                  }
              });
              //表单检查不通过
              if (checkform) return false;
              param.gender = $('input[name="gender"]:checked', register).val();
              <!--{if $user.openid}-->
              //绑定账号 接收用户信息
              param.openid = "<!--{$user.openid}-->";
              param.platform = "<!--{$user.platform}-->";
              <!--{/if}-->
              <!--{if $iCMS.CONFIG.user.register.seccode }-->
                  //检查验证码
                  param.register_seccode = true;
              <!--{/if}-->
              iCMS.run('passport', function($PASSPORT) {
                  //注册成功 事件绑定
                  $PASSPORT.SUCCESS = function(s) {
                      // console.log('****',s);
                      window.top.location.href = "<!--{$forward}-->";
                  }
                  //注册失败 事件绑定
                  $PASSPORT.FAIL = function(f) {
                      iCMS.UI.seccode(".seccode-img", register);
                      tip(f);
                  }
                  //提交参数
                  $PASSPORT.REGISTER(param);
              });
          });
          function check_form(a) {
              var ret = {
                  forward: a.name,
                  msg: 'ok'
              }
              if (a.value == "") {
                  ret.msg = 'empty';
                  return tip(ret);
              }
              var ajax_check = false;
              switch (a.name) {
                  case 'username':
                      var pattern = /^([a-zA-Z0-9._-])+@([a-zA-Z0-9_-])+(\.[a-zA-Z0-9._-])+/;
                      if (!pattern.test(a.value)) {
                          ret.msg = 'error';
                          return tip(ret);
                      }
                      ajax_check = true;
                      break;
                  case 'nickname':
                      var length = a.value.replace(/[^\x00-\xff]/g, 'xx').length;
                      if (length < 4) {
                          ret.msg = 'error';
                          return tip(ret);
                      }
                      if (length > 20) {
                          ret.msg = 'error';
                          return tip(ret);
                      }
                      ajax_check = true;
                      break;
                  case 'password':
                      if (a.value.length < 6) {
                          ret.msg = 'error';
                      }
                      return tip(ret);
                      break;
                  case 'rstpassword':
                      var pwd = $("input[name='password']").val();
                      if (pwd.length < 6) {
                          ret.msg = 'len_error';
                      }
                      if (pwd != a.value) {
                          ret.msg = 'error';
                      }
                      return tip(ret);
                      break;
                  case 'seccode':
                      ajax_check = true;
                      break;
                  case 'agreement':
                      checked = $('input[name="agreement"]', register).prop("checked");
                      if (!checked) {
                          ret.msg = 'def';
                      }
                      return tip(ret);
                      break;
                  default:
                      $("input[name='" + a.name + "']").data('check', true);
              }
              if (ajax_check) {
                  iCMS.run('passport', function($PASSPORT) {
                      $PASSPORT.CHECK({
                              name: a.name,
                              value: a.value
                          },
                          function() { //CHECK成功 事件
                              tip(ret);
                          },
                          function(f) { //CHECK失败 事件
                              if (a.name == 'seccode') {
                                  iCMS.UI.seccode(".seccode-img", register);
                              }
                              tip(f);
                          }
                      );
                  });
              };
          }
          function tip(a) {
              var info = {
                  'error_username': '电子邮箱格式不正确！',
                  'error_nickname': '昵称只能4~20位，每个中文字算2位字符。',
                  'error_password': '密码太短啦，至少要6位哦',
                  'error_rstpassword': '密码与确认密码不一致！',
                  'len_error_rstpassword': '请重复输入一次密码！',
                  'error_ajax_username': '邮件地址已经注册过了,请直接登录或者换个邮件再试试。',
                  'error_ajax_nickname': '昵称已经被注册了,请换个再试试。',
                  'error_ajax_seccode': '',
                  'empty_username': '请填写电子邮箱！',
                  'empty_nickname': '请填写昵称！',
                  'empty_password': '请填写密码！',
                  'empty_rstpassword': '请重复输入一次密码！',
                  'empty_seccode': '请输入验证码！',
                  'def_username': '请填写正确的常用邮箱，以便找回密码。<br />比如：example@example.com',
                  'def_nickname': '支持中文，不能以数字开头，最多20个字符，中文算两个字符。',
                  'def_password': '6-20个字母、数字或者符号',
                  'def_rstpassword': '这里要重复输入一下你的密码',
                  'def_seccode': '请输入图片中的字符!',
                  'def_agreement': '请勾选同意网络服务使用协议'
              }
              var name = a.forward,
                  type = a.msg;
              var tip = $('.tip-' + name),
                  input = $("input[name='" + name + "']");
              // console.log(a);
              if (type == "ok") {
                  tip.hide();
                  input.data('check', true);
              } else if (type && type != "ok") {
                  // if(name=='seccode') iCMS.UI.seccode(".seccode-img",register);
                  var text = info[type + '_' + name] || a.msg;
                  tip.html(text).addClass('tip-error');
                  input.data('check', false);
              }
          }
      });
    </script>
  </head>
  <body class="userApp passport">
    <!--{include file="./user.header.htm" import="true"}-->
    <div class="container">
      <div id="register-box" class="wrapper">
        <div class="logo">
          <a href="<!--{$site.url}-->">
            <img src="<!--{$site.urls.tpl}-->/static/img/iCMS.LOGO.png" />
          </a>
        </div>
        <!--{if $user}-->
        <div class="alert alert-warning" role="alert" style="margin-top: 10px;margin-bottom: 10px;">
          <strong>*</strong>请先补充必要的个人信息，只有补充完这些信息才能真正加入<!--{$site.title}-->哦
        </div>
        <!--{/if}-->
        <div class="form-group">
          <!-- <label for="username">电子邮箱</label> -->
          <input type="text" placeholder="电子邮箱" name="username" id="username" class="form-control">
          <span class="help-block tip-username">请填写正确的常用邮箱，以便找回密码。<br />比如：example@example.com</span>
        </div>
        <div class="form-group">
          <!-- <label for="nickname">昵称</label> -->
          <input type="text" placeholder="昵称" name="nickname" id="nickname" class="form-control">
          <span class="help-block tip-nickname">不能以数字开头，最多20个字符，中文算两个字符。</span>
        </div>
        <div class="radio">
          <label class="radio-inline" for="gender-girl">
            <input type="radio" value="girl" id="gender-girl" name="gender" checked="checked">
            <span>女</span>
          </label>
          <label class="radio-inline" for="gender-boy">
            <input type="radio" value="boy" id="gender-boy" name="gender">
            <span>男</span>
          </label>
        </div>
        <div class="form-group">
          <!-- <label for="password">密 码</label> -->
          <input type="password" placeholder="请输入您的密码" name="password" id="password" class="form-control">
          <span class="help-block tip-password">6-20个字母、数字或者符号</span>
        </div>
        <div class="form-group">
          <!-- <label for="rstpassword">确认密码</label> -->
          <input type="password" placeholder="请在一次输入您的密码" name="rstpassword" id="rstpassword" class="form-control">
          <span class="help-block tip-rstpassword">这里要重复输入一下你的密码</span>
        </div>
        <!--{if $iCMS.CONFIG.user.register.seccode }-->
        <div class="form-group seccode-wrap">
          <!-- <label for="seccode">验证码</label> -->
          <input type="text" placeholder="验证码" id="seccode" name="seccode" class="form-control">
          <!--{iCMS:public:seccode}-->
          <span class="help-block tip-seccode">请输入图片中的字符!</span>
        </div>
        <!--{/if}-->
        <div class="checkbox">
          <label for="reg_agreement">
            <input type="checkbox" name="agreement" id="reg_agreement" checked="checked">
            <span>
              我已看过并同意《<a href="<!--{iCMS:router url='public:agreement'}-->" target="_blank"><!--{$site.title}-->网络服务使用协议</a>》
            </span>
          </label>
        </div>
        <div class="clearfix mt10">
          <button type="submit" id="register_submit" class="btn btn-primary btn-lg btn-block">注 册</button>
        </div>
        <div class="clearfix mt10">
          <a class="btn btn-success" href="<!--{iCMS:router url='user:login' query="$query"}-->" style="margin-top: 8px;">
            <i class="fa fa-user"></i> 已经有帐号？请直接登录 »
          </a>
        </div>
        <!--{if !$user}-->
        <hr />
        <div class="open-btn">
          <h3 class="gray mb10">您也可以用以下方式登录：</h3>
          <!--{if $iCMS.CONFIG.user.open.QQ.enable }-->
          <a class="btn btn-primary btn-sm" href="<!--{iCMS:router url='user:login:qq'}-->"><i class="fa fa-qq"></i> QQ 登录</a>
          <!--{/if}-->
          <!--{if $iCMS.CONFIG.user.open.WB.enable }-->
          <a class="btn btn-danger btn-sm" href="<!--{iCMS:router url='user:login:wb'}-->"><i class="fa fa-weibo"></i> 微博登录</a>
          <!--{/if}-->
          <!--{if $iCMS.CONFIG.user.open.WX.enable }-->
          <a class="btn btn-success btn-sm" href="<!--{iCMS:router url='user:login:wx'}-->"><i class="fa fa-weixin"></i> 微信登录</a>
          <!--{/if}-->
        </div>
        <!--{/if}-->
      </div>
    </div>
    <div class="clearfix mt10"></div>
    <!--{include file="iCMS://footer.htm"}-->
  </body>
</html>
